#! /bin/bash
if [[ $1 == "" ]]
then
TD_DATE=`date -d '-1 day' "+%Y-%m-%d"`
else
TD_DATE=$1
fi

V_YEAR=$(date -d "${TD_DATE}" +%Y)
V_MONTH=$(date -d "${TD_DATE}" +%m)
V_TABLE_web_chat_ems="web_chat_ems_${V_YEAR}_${V_MONTH}"
V_TABLE_web_chat_text_ems="web_chat_text_ems_${V_YEAR}_${V_MONTH}"

sqoop import --connect jdbc:mysql://192.168.52.150:3306/nev \
--username root --password 123456 \
--query "select id,
       create_date_time,
       session_id,
       sid,
       create_time,
       seo_source,
       seo_keywords,
       ip,
       area,
       country,
       province,
       city,
       origin_channel,
       user as user_match,
       manual_time,
       begin_time,
       end_time,
       last_customer_msg_time_stamp,
       last_agent_msg_time_stamp,
       reply_msg_count,
       msg_count,
       browser_name,
       os_info,
       '${TD_DATE}' as starts_time
       from ${V_TABLE_web_chat_ems}
       where create_time between '${TD_DATE} 00:00:00' and '${TD_DATE} 23:59:59' and \$CONDITIONS" \
       --hcatalog-database itcast_ods \
       --hcatalog-table web_chat_ems_demo \
       --hive-partition-key starts_time \
       --hive-partition-value ${TD_DATE} \
       -m 100 \
       --split-by id

sqoop import --connect jdbc:mysql://192.168.52.150:3306/nev \
--username root --password 123456 \
--query "select id,
        referrer,
        from_url,
        landing_page_url,
        url_title,
        platform_description,
        other_params,
        history,
        '${TD_DATE}' as start_time
    from ${V_TABLE_web_chat_text_ems} wcte,
        (select id as wce_id, create_time
        from ${V_TABLE_web_chat_ems}
        where create_time between '${TD_DATE} 00:00:00' and '${TD_DATE} 23:59:59') wce
    where wcte.id = wce.wce_id
    and \$CONDITIONS" \
    --hcatalog-database itcast_ods \
    --hcatalog-table web_chat_text_ems_demo \
    --hive-partition-key start_time \
    --hive-partition-value ${TD_DATE} \
    -m 100 \
    --split-by id